package com.client.action;

import com.client.service.MenuClientService;
import com.data.util.CheckDataUtils;
import com.data.util.FinalStringUtils;
import com.data.util.JsonUtils;
import com.data.util.SoftwareMassageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


/**
 * 菜单管理
 *
 * @author:HingLo
 * @create 2017-10-11 13:48
 **/
@Controller
@RequestMapping("/menuClient/client/")
public class MenuClientAction {

    @Autowired
    private MenuClientService menuClientService;


    @RequestMapping("findMenuOneClient")
    @ResponseBody
    public Map<String, Object> findMenuOneClientAction(Integer type, String id, HttpServletRequest request) {
        if (type == FinalStringUtils.GAMETYPE || type == FinalStringUtils.SOFTTYPE) {
            //分类的菜单是软件或者是游戏
            List<?> list;
            if (CheckDataUtils.stringUtils(id)) {
                list = menuClientService.findMenuTwoClientService(id);
            } else {
                list = menuClientService.findMenuClientService(type);
            }
            String[] value = {"id", "fid", "name"};
            return SoftwareMassageUtils.getSoftwareMassageUtils(list, request, null, value);
        }
        return JsonUtils.detailListToMapUtils(null, null);
    }

    /**
     * 查找分类下的数据的软件信息
     *
     * @param id    二级分类的id
     * @param start 开始位置
     * @param end   结束位置
     * @return
     */
    @RequestMapping("findMenuSoftware")
    @ResponseBody
    public Map<String, Object> findMenuSoftwareAction(String id, int start, int end, HttpServletRequest request) {
        if (CheckDataUtils.stringUtils(id)) {
            List<?> list = menuClientService.findMenuSoftwareAction(id, start, end);
            return SoftwareMassageUtils.getSoftwareMassageUtils(list, request);
        }
        return JsonUtils.detailListToMapUtils(null, null);
    }


}
